package yunjiao.javatutorials.designpatterns.interpreter.expr;

import yunjiao.javatutorials.designpatterns.interpreter.Employee;
import yunjiao.javatutorials.designpatterns.interpreter.Manager;

/**
 * TODO
 *
 * @author yangyunjiao
 */
public class ManagerOfExpression extends TerminalExpression {

    protected String name;

    public ManagerOfExpression(String name) {
        this.name = name;
    }

    @Override
    public boolean interpret(Employee context) {
        if (context.isManager()) {
            Manager manager = (Manager) context;
            return manager.getManagingEmployees().stream()
                    .map(managingEmployee -> managingEmployee.getEmployeeName().toLowerCase())
                    .toList().contains(name.toLowerCase());
        }
        return false;
    }

    @Override
    public String toString() {
        return "ManagerOfExpression [name=" + name + "]";
    }
}
